﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClientDBAgent;
using HF.Permission.Data;
using HF.Framework.Web;

public partial class LogMgr : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            YYSimpleCalendar1.Text = DateTime.Now.ToShortDateString();
            YYSimpleCalendar2.Text = DateTime.Now.AddDays(10).ToShortDateString();
            bind();

        }
    }
    private void bind()
    {
        string sql = "select * from HF_Logs where LogDatetime>=@begintime and LogDatetime<=@endtime ";
        SqlDataItem sqlItem = new SqlDataItem();
        sqlItem.AppendParameter("@begintime", YYSimpleCalendar1.Text);
        sqlItem.AppendParameter("@endtime", YYSimpleCalendar2.Text);
        if (cbxType.Checked == true)
        {
            sql = sql + " and LogType=@LogType";
            sqlItem.AppendParameter("@LogType", tbxType.Text);
        }
        else
        {
            sql = sql + " and 1=@LogType";
            sqlItem.AppendParameter("@LogType", 1, typeof(int));
        }
        sqlItem.CommandText = sql + " order by LogId desc ";
        ClientDBAgent agent = new ClientDBAgent();
        DataTable dt = agent.ExecuteDataTable(sqlItem);
        gvLog.DataSource = dt;
        gvLog.DataBind();
       
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        bind();
       
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string UserId = User.Identity.Name.ToString();
        bool ispass = PurviewData.GetInstance().IsPower(UserId, "000001");
        if (ispass == false)
        {
            WorkDialog.ShowMessage(this,"没有删除日志的权限,请与管理员联系!");
            return;
        }
        foreach (GridViewRow gvr in gvLog.Rows)
        {
            CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
            if (ch.Checked)
            {
                SqlDataItem sqlItem = new SqlDataItem();
                sqlItem.CommandText = "delete from HF_Logs where LogId=@LogId";
                sqlItem.AppendParameter("@LogId", gvLog.DataKeys[gvr.DataItemIndex].Value.ToString());
                ClientDBAgent agent = new ClientDBAgent();
                agent.ExecuteNonQuery(sqlItem);
                
                
            }
        }
        bind();

       
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {

    }
}
